<template>
  <div id="game">
    <div class="restart" @click="reStart()">
      <div class="restart-text">重开</div>
    </div>
    <div id="cases">
      <div class="cases-container">
        <div v-if="isStartGame">
          <div id="object">
            {{events[id].place}}
          </div>
          <div class="line"></div>
          <div id="event">
            {{events[id].result}}
          </div>
          <div class="clear"></div>
        </div>
        <div v-if="!isStartGame">
          <div class="game-title">从今天开始新生活</div>
        </div>
      </div>
    </div>
    <div id="selections">
      <div class="selections-container">
        <div v-if="isStartGame" id="button-list">
          <div v-for="selection in events[id].selections" :key="selection" class="selection-button" @click="entryEvent(selection)">
            <div class="button-text">{{events[selection].cause}}</div>
          </div>
        </div>
        <div v-if="!isStartGame">
          <div class="start-button" @click="startGame()">
            <div class="start-button-text">开始游戏</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isStartGame: false,
      events: require("../assets/data/events.json"),
      id: this.$store.state.nowId
    }
  },
  methods: {
    entryEvent(id) {
      this.id = id
      this.$store.commit("setNowId", id)
      console.log(this.id);
    },
    startGame() {
      this.isStartGame = true
    },
    reStart() {
      this.id = "0000";
      this.$store.commit("setNowId", "0000")
      this.isStartGame = false
    }
  }
};
</script>

<style>
.restart {
  position: absolute;
  width: 50px;
  height: 50px;
  right: 0px;
  border-radius: 50%;
  background-color: #555555;
  color: #eeeeee;
}
.restart:hover {
  animation-name: start-button-hover;
  animation-duration: 500ms;
  animation-fill-mode: forwards;
}
@keyframes start-button-hover {
  100% {
    background-color: #333333;
    color: #aaaaaa;
  }
}
.restart-text {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}
#game {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  height: 100%;
}
#cases {
  width: 100%;
  height: 50%;
}
.cases-container {
  --width-value: 60%;
  position: relative;
  width: var(--width-value);
  height: auto;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
@media (max-width: 640px) {
  .cases-container {
    --width-value: 90%;
  }
}
.clear {
  clear: both;
}
#object {
  position: relative;
  color: #eeeeee;
  float: left;
  font-size: 1.5rem;
  margin: 0.5rem;
}
.line {
  position: relative;
  clear: both;
  width: 100%;
  height: 0.3rem;
  background-color: #eeeeee;
}
#event {
  font-size: 1.1rem;
  margin: 10px 1rem 0.5rem 1rem;
  color: #eeeeee;
  text-align: left;
}
#selections {
  width: 100%;
  height: 50%;
}
.selections-container {
  --width-value: 60%;
  position: relative;
  width: var(--width-value);
  height: auto;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
@media (max-width: 640px) {
  .selections-container {
    --width-value: 90%;
  }
}
.selection-button {
  position: relative;
  width: 100%;
  border-radius: 10px;
  height: 3rem;
  background-color: #555555;
  text-align: center;
  margin-bottom: 10px;
  color: #eeeeee;
}
.selection-button:hover {
  animation-name: selection-button-hover;
  animation-duration: 500ms;
  animation-fill-mode: forwards;
}
@keyframes selection-button-hover {
  100% {
    background-color: #333333;
    color: #aaaaaa;
  }
}
.button-text {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}
.game-title {
  font-size: 3rem;
  color: #eeeeee;
}
.start-button {
  position: relative;
  width: 100%;
  border-radius: 10px;
  height: 5rem;
  background-color: #555555;
  text-align: center;
  color: #eeeeee;
}
.start-button-text {
  font-size: 2rem;
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}
.start-button:hover {
  animation-name: start-button-hover;
  animation-duration: 500ms;
  animation-fill-mode: forwards;
}
@keyframes start-button-hover {
  100% {
    background-color: #333333;
    color: #aaaaaa;
  }
}
</style>
